using System;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;

namespace WMVConvert.Metadata
{
	public static class MediaKind
	{
		public static readonly Guid None = Guid.Empty;
		/// <summary>
		/// Use for audio book files.
		/// </summary>
		public static readonly Guid AudioBook = new Guid("{E0236BEB-C281-4EDE-A36D-7AF76A3D45B5}");
		/// <summary>
		/// Use for audio files that contain spoken word, but are not audio books. For example, stand-up comedy routines.
		/// </summary>
		public static readonly Guid AudioSpoken = new Guid("{3A172A13-2BD9-4831-835B-114F6A95943F}");
		/// <summary>
		/// Use for audio files related to news.
		/// </summary>
		public static readonly Guid AudioNews = new Guid("{6677DB9B-E5A0-4063-A1AD-ACEB52840CF1}");
		/// <summary>
		/// Use for audio files with talk show content.
		/// </summary>
		public static readonly Guid AudioTalkShow = new Guid("{1B824A67-3F80-4E3E-9CDE-F7361B0F5F1B}");
		/// <summary>
		/// Use for video files related to news.
		/// </summary>
		public static readonly Guid VideoNews = new Guid("{1FE2E091-4E1E-40CE-B22D-348C732E0B10}");
		/// <summary>
		/// Use for video files containing Web-based shows, short films, movie trailers, and so on. This is the general identifier for video entertainment that does not fit into another category.
		/// </summary>
		public static readonly Guid WebVideo = new Guid("{D6DE1D88-C77C-4593-BFBC-9C61E8C373E3}");
		/// <summary>
		/// Use for audio files containing sound clips from games.
		/// </summary>
		public static readonly Guid SoundClip = new Guid("{00033368-5009-4AC3-A820-5D2D09A4E7C1}");
		/// <summary>
		/// Use for audio files containing complete songs from game sound tracks. If only part of a song is encoded in the file, use the identifier for game sound clips instead.
		/// </summary>
		public static readonly Guid GameSoundTrack = new Guid("{F24FF731-96FC-4D0F-A2F5-5A3483682B1A}");
		/// <summary>
		/// Use for video files containing music videos.
		/// </summary>
		public static readonly Guid MusicVideo = new Guid("{E3E689E2-BA8C-4330-96DF-A0EEEFFA6876}");
		/// <summary>
		/// Use for video files containing general home video.
		/// </summary>
		public static readonly Guid HomeVideo = new Guid("{B76628F4-300D-443D-9CB5-01C285109DAF}");
		/// <summary>
		/// Use for video files containing feature films.
		/// </summary>
		public static readonly Guid Movie = new Guid("{A9B87FC9-BD47-4BF0-AC4F-655B89F7D868}");
		/// <summary>
		/// Use for video files containing television shows. For Web-based shows, use the more generic identifier.
		/// </summary>
		public static readonly Guid TVShow = new Guid("{BA7F258A-62F7-47A9-B21F-4651C42A000E}");
		/// <summary>
		/// Use for video files containing corporate video. For example, recorded meetings or training videos.
		/// </summary>
		public static readonly Guid CorporateVideo = new Guid("{44051B5B-B103-4B5C-92AB-93060A9463F0}");
		/// <summary>
		/// Use for video files containing home video made from photographs.
		/// </summary>
		public static readonly Guid HomeVideoFromPictures = new Guid("{0B710218-8C0C-475E-AF73-4C41C0C8F8CE}");
	}

	public class WMMediaKindValue : WMBinary<Guid>
	{
		public WMMediaKindValue()
			: base(Guid.Empty)
		{
		}

		public WMMediaKindValue(string value)
		{
			Guid guidValue = Guid.Empty;
			FieldInfo field = typeof(MediaKind).GetField(value, BindingFlags.Public | BindingFlags.Static);
			if (field != null)
			{
				guidValue = (Guid)field.GetValue(null);
			}
			else
			{
                guidValue = new Guid(value);
			}
			Init(guidValue);
		}

		public WMMediaKindValue(IntPtr pValue, uint length)
			: base(pValue, length)
		{
		}

		public WMMediaKindValue(Guid value)
			: base(value)
		{
		}

		public override string ToString()
		{
			string name = typeof(MediaKind).GetFields(BindingFlags.Public | BindingFlags.Static)
				.Where(x => ((Guid)x.GetValue(null)) == this.Value)
				.Select(x => x.Name)
				.FirstOrDefault();
			if (string.IsNullOrEmpty(name))
			{
				return base.ToString();
			}
			return name;
		}
	}
}
